var form;
var tableIns;
var ctxPath = '/'
$(function () {
    layui.config({
        base: ctxPath + 'lib/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index'//主入口模块
    }).use(['index', 'table', 'form'], function () {
        var table = layui.table;
        form = layui.form;
        // 渲染表格
        tableIns = table.render({
            elem: '#table',
            toolbar: '#table-title',
            url: 'nasLogPager',
            page: true,
            cols: [[
                // {type: 'numbers'},
                {field: 'cyqxh', title: '查验区序号', align: 'center'},
                {
                    field: 'cyqmc', title: '查验区名称', align: 'center'
                },
                {field: 'ip', title: 'IP地址', align: 'center'},
                {field: 'naslocation', title: '云盘路径', align: 'center'},
                {field: 'createdate', title: '扫描时间', align: 'center' },
                {
                    field: 'status', title: '状态', align: 'center', templet: function (d) {
                        var status = d.status;
                        switch (status) {
                            case '1':
                                status = "正常";
                                break;
                            case '2':
                                status = "掉线";
                                break;
                            default:
                                status = d.status;
                                break;
                        }
                        return status;
                    }
                }

            ]],
            request: {
                pageName: 'page' //页码的参数名称，默认：page
                , limitName: 'limit' //每页数据量的参数名，默认：limit
            }
        });
        initOrganSelect();
        //监听行工具事件
        table.on('tool(table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'view') {
                openView(data)
            }
        });
        //监听提交
        form.on('submit(searchSubmit)', function () {
            tableIns.reload({
                where: {
                    cyqxh: $("#cyqxh").val(),
                    cyqmc: $("#cyqmc").val()
                },
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false;
        });
    });
})
function initOrganSelect() {
    $.ajax({
        type: "GET",
        url: ctxPath + "system/organization/organList",
        success: function (res) {
            var data = res.obj;
            for (var i = 0; i < data.length; i++) {
                $("#cyqxh").append("<option value='" + data[i].cyqxh + "'>" + data[i].name + "</option>")
            }
            renderForm();
        }
    });
}